def er(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True


n = input()
if len(n) != 4:
       print(0)
       exit(0)
num = [int(n[0]), int(n[1]), int(n[2]), int(n[3]), int(n[0:2]), int(n[0:3]), int(n[1:3]), int(n[1:4]),
       int(n[2:4]), int(n)]
res = []
for i in num:
       if er(i) == True:
           res.append(i)
if len (res) > 0:
       print(max(res))
else:
       print(0)
